<?php
require_once('header.php');
include("adodb5/adodb-exceptions.inc.php");
include('adodb5/adodb.inc.php');

$strDsn = 'mssql://influenza:inf123456@10.1.251.14';
$strIdDelegacion = 3;
$strHtmlOutput = '';

$cnn = ADONewConnection($strDsn);
$cnn->SetFetchMode(ADODB_FETCH_ASSOC);

if($cnn)
{
//
	$strSql = "SELECT	US.id_unidad, 
						LTRIM(RTRIM(US.nombre + ' (' + DL.corto + '.) - CLUE:' + US.clues)) AS nombre 
						FROM	Catalogos.dbo.unidades_salud AS US 
						INNER JOIN Catalogos.dbo.delegaciones AS DL 
						ON US.id_delegacion = DL.id_delegacion 
						WHERE US.activo LIKE '1' 
						AND LEN(US.clues) = 11 
						AND DL.id_delegacion = $strIdDelegacion  
						ORDER BY nombre ASC";
	
	$rs = $cnn->Execute($strSql);
	
	if($rs)
	{
	//
		$intNoRows = $rs->RecordCount();
		
		if($intNoRows > 0)
		{
		//
			$strHtmlOutput .=	'<select name="cboUnidades" id="cboUnidades" onfocus="javascript: $(\'divUserAddMsg\').update(\'Seleccione una unidad m&eacute;dica.\');" onblur="javascript: $(\'divUserAddMsg\').update(\'\');">';

			while(!$rs->EOF)
			{
			//
				$rs->FetchInto($arrCurrentRow);
				$strIdUnidad = $arrCurrentRow['id_unidad'];
				$strNombre = htmlentities($arrCurrentRow['nombre']);
				$strHtmlOutput .=	"<option value=\"$strIdUnidad\">$strNombre</option>\n";

			}
			
			$strHtmlOutput .= '</select>';
			
		} else {
		//
		}
		
		$rs->Close();
		
		print $strHtmlOutput;
		
	} else {
	//
		print "rs fail";
	}
	
	$cnn->Close();
	
} else {
//
	print "fail";
}

?>